package com.fashion.service;

import com.fashion.dao.NewsRecordDao;
import com.fashion.model.NewsRecord;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: gnyk
 * Date: 13-9-3
 */
@Service("newsRecordService")
public class NewsRecordServiceImpl implements  NewsRecordService{
    private NewsRecordDao newsRecordDao;

    @Override
    public void saveOrUpdate(Object object) {
        newsRecordDao.saveOrUpdate(object);
    }

    @Override
    public void deleteEntityById(String id) {
       newsRecordDao.deleteById(id, NewsRecord.class);
    }

    @Override
    public void deleteEntity(Object object) {
        newsRecordDao.delete(object);
    }

    @Override
    public List<NewsRecord> searchRecordByCreatorId(String creatorId) {
        String hql = "from NewsRecord r where r.creatorId = :creatorId";
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("creatorId", creatorId);

        return newsRecordDao.findItems(hql,parameters);
    }

    @Resource(name = "newsRecordDao")
    public void setNewsRecordDao(NewsRecordDao newsRecordDao) {
        this.newsRecordDao = newsRecordDao;
    }
}
